package com.ygxsk.carhome.ui.paintbook;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alipay.sdk.app.PayTask;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.Toaster;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.tencent.mmkv.MMKV;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.yanzhenjie.permission.Action;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.runtime.Permission;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.botdialog.BaseBottomDialog;
import com.ygxsk.carhome.botdialog.BottomDialog;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.enumwrap.PayType;
import com.ygxsk.carhome.event.EventPaintBookingMain;
import com.ygxsk.carhome.event.EventPay;
import com.ygxsk.carhome.helper.PushConstants;
import com.ygxsk.carhome.listener.AuthorityCallbackListener;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.listener.ErrorParentExtraSingle;
import com.ygxsk.carhome.permission.PermissionSetting;
import com.ygxsk.carhome.permission.RuntimeRationale;
import com.ygxsk.carhome.response.AlipayPayBean;
import com.ygxsk.carhome.response.BookingInsideBean;
import com.ygxsk.carhome.response.BookingOutsideBean;
import com.ygxsk.carhome.response.PaintBookingPayFee;
import com.ygxsk.carhome.response.PayParameterResult;
import com.ygxsk.carhome.response.PayTypeListBean;
import com.ygxsk.carhome.response.WechatPayBean;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.sys.PermissionInterceptor;
import com.ygxsk.carhome.sys.PermissionNameConvert;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.BookingOutsideAdapter;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;
import com.ygxsk.carhome.views.MyLinearLayoutManager;
import com.ygxsk.carhome.views.OnPasswordInputFinish;
import com.ygxsk.carhome.views.PasswordView;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-09-25  16:28
 * @Description: 订单结算页面
 */
public class PaintBookingFeeActivity extends ErrorActivity implements ErrorParentExtraSingle {

    //去结算的按钮 点击
    @BindView(R.id.roundButtonInBookingPayFee)
    RoundTextView roundButtonInBookingPayFee;

    //该页面的刷新操作
    @BindView(R.id.refreshLayoutInBookingPayFee)
    SmartRefreshLayout refreshLayoutInBookingPayFee;

    //该页面的直接房间和时间段列表
    @BindView(R.id.recyclerViewInBookingPayFee)
    RecyclerView recyclerViewInBookingPayFee;

    /**
     * 支付面板内容。
     */
    private BaseBottomDialog payDialogPanel;

    //footerview 是结算列表
    private PaintBookingPayFee extra_paintBookingPayFee;
    //重新调用接口的参数
    private String extra_paint_booking_payfee_parameter;

    //适配器
    private BookingOutsideAdapter bookingOutsideAdapter;
    //适配器的总数据
    private ArrayList<BookingOutsideBean> mDataResources = new ArrayList<>();


    //底部的支付列表适配器；
    private PayFeeWayFooter payFeeWayFooter;
    private ArrayList<PayTypeListBean> footerDataResources = new ArrayList<>();

    //喷涂币的支付密码
//    private String passwordStringPass;
    //做上传 选中的房间号和该房间预约时间段-这里的outSide标识的 是外侧的喷涂房间
    private ArrayList<PaintBookIngSiteOutSideUpLoad> siteList_upLoad = new ArrayList<>();

    //--------------------------------------------------------------------------------------
    //支付宝的支付标识内容
    private static final int SDK_PAY_FLAG = 1;

    private Handler mHandler = new Handler(Looper.getMainLooper()) {

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

            switch (msg.what) {

                case SDK_PAY_FLAG: {//支付处理内容。。。

                    @SuppressWarnings("unchecked")
                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);

                    /**
                     对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。
                     */
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();

                    // 判断resultStatus 为9000则代表支付成功
                    if (TextUtils.equals(resultStatus, PushConstants.ALIPAY_9000)) {

                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
                        ToastUtils.showShort(R.string.alipay_pay_success);
//                        gainOrderState(payTokenForPay, 1);//支付成功跳转到结算结果页面。

                        method_handler_success();

                    } else {

                        // 该笔订单真实的支付结果，需要依赖服务端的异步通知。
                        ToastUtils.showShort(R.string.alipay_pay_error);

                        //2018年03月20日更改该逻辑，支付失败停留在该界面。
                        //gainOrderStateFail(payTokenForPay, 0);//支付成功跳转到结算结果页面。

                    }

                    break;
                }

                default:
                    break;
            }


        }
    };

    @OnClick({R.id.roundButtonInBookingPayFee})//【结算】按钮
    public void onViewClickInPaintBookingPayFee(View viewInside) {

        switch (viewInside.getId()) {

            case R.id.roundButtonInBookingPayFee: {

                //首先校验 是否选中【支付方式】，不然不知道走哪种结算：
                String payType = "";

                if ((extra_paintBookingPayFee.getPayTypeList() != null) && (!extra_paintBookingPayFee.getPayTypeList().isEmpty())) {

                    for (PayTypeListBean payTypeListBeanItem : extra_paintBookingPayFee.getPayTypeList()) {

                        int isChecked = payTypeListBeanItem.getIsChecked();

                        if (isChecked == 1) {
                            payType = payTypeListBeanItem.getPayType();
                        }
                    }
                }

                //如果勾选的支付方式是空值，那么就是 用户没有选中支付方式；
                if (TextUtils.isEmpty(payType)) {
                    CommUtils.checkDialog(mAlertView);
                    mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.please_input_pay_type), true);
                    mAlertView.show();
                    return;
                }

                //判断各种支付方式 是哪种
                if (TextUtils.equals(payType, PayType.PAYTYPE_PAINTMONEY.getIndex())) {

                    //喷涂币支付，是否要先校验余额是否充足？
                    //直接调用接口
                    method_paymentPanelOrWechatOrAliPay(PayType.PAYTYPE_PAINTMONEY.getIndex(), "");

                } else if (TextUtils.equals(payType, PayType.PAYTYPE_WECHAT.getIndex())) {

                    //微信支付的 各种返回信息的填充
                    method_paymentPanelOrWechatOrAliPay(PayType.PAYTYPE_WECHAT.getIndex(), "");

                } else if (TextUtils.equals(payType, PayType.PAYTYPE_ALIPAY.getIndex())) {

                    method_paymentPanelOrWechatOrAliPay(PayType.PAYTYPE_ALIPAY.getIndex(), "");

                } else if (TextUtils.equals(payType, PayType.PAYTYPE_MOUTH_PAY.getIndex())) {

                    method_paymentPanelOrWechatOrAliPay(PayType.PAYTYPE_MOUTH_PAY.getIndex(), "");

                } else {

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "没有执行逻辑");

                    ToastUtils.showShort(R.string.get_pay_way_abnomal);

                }

                break;

            }

            default:
                break;
        }

    }


    private IWXAPI mWinXinApi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        processExtraData();

        initloading();

        initViews();

//        gainDatas();

        //retain

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

    }

    @Override
    protected int getContentViewId() {

        mWinXinApi = WXAPIFactory.createWXAPI(this, PushConstants.WEIXIN_APPID);//红色物业的id

        if (mWinXinApi != null) {//将该app注册到微信

            mWinXinApi.registerApp(PushConstants.WEIXIN_APPID);

            //建议动态监听微信启动广播进行注册到微信
            registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    // 将该app注册到微信
                    mWinXinApi.registerApp(PushConstants.WEIXIN_APPID);
                }
            }, new IntentFilter(ConstantsAPI.ACTION_REFRESH_WXAPP));

        }

        return R.layout.activity_paint_booking_fee;
    }


    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.title_paintbooking_feel));//结算页
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);

        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });

        toolbarHelper.setLayoutRight(false, 0, "", null);

//        toolbarHelper.setLayoutRight(true, 1, "历史记录", new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//
//                //这个也是更多，跳转到选项卡列表页，携带搜索？
//                Bundle extra_bundle = new Bundle();
//                //这里的更多是单个人的更多？还是包裹所有人的？
////                ActivityUtils.startActivity(SmartGoOutActivity.this, CardDistHistoryActivity.class);
////                ActivityUtils.startActivity(SmartGoOutActivity.this, SmartGoRecordHistoryActivity.class);
//                  ActivityUtils.startActivity(SmartGoOutActivity.this, SmartGoSumHistoryActivity.class);
//
//            }
//        });


    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {

        //填充适配器
//        BookingPayFeeOutsideAdapter bookingPayFeeOutsideAdapter = new BookingPayFeeOutsideAdapter();

        if (extra_paintBookingPayFee != null) {

            recyclerViewInBookingPayFee.setLayoutManager(new MyLinearLayoutManager(this));

//            bookingOutsideAdapter = new BookingOutsideAdapter(R.layout.bookingoutsideadapter, extra_paintBookingPayFee.getSiteList(), ExtraValue.COME_FROM_PAINT_BOOKING_FEE_ACTIVITY);
            bookingOutsideAdapter = new BookingOutsideAdapter(R.layout.bookingoutsideadapter, mDataResources, ExtraValue.COME_FROM_PAINT_BOOKING_FEE_ACTIVITY);
            bookingOutsideAdapter.removeAllHeaderView();
            bookingOutsideAdapter.removeAllFooterView();

            bookingOutsideAdapter.addHeaderView(getHeaderView(recyclerViewInBookingPayFee));
            bookingOutsideAdapter.addFooterView(getFooterView(recyclerViewInBookingPayFee));

            recyclerViewInBookingPayFee.setAdapter(bookingOutsideAdapter);
            bookingOutsideAdapter.notifyDataSetChanged();

        } else {
            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "extra_paintBookingPayFee 是空的");
        }

        if (refreshLayoutInBookingPayFee != null) {

            refreshLayoutInBookingPayFee.setOnRefreshListener(new OnRefreshListener() {
                @Override
                public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                    refreshLayout.getLayout().post(new Runnable() {
                        @Override
                        public void run() {

//                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "refreshLayoutInBooking--下拉刷新执行");

                            //可以直接再次刷新下接口，那需要给传参携带来；
                            gainDatas();

                            refreshLayout.finishRefresh();

                        }
                    });

                }
            });

        }


        //页面的手动刷新

    }

    private View getHeaderView(RecyclerView _recyclerViewWork) {

        View workHeader;
        if ((_recyclerViewWork != null) && (_recyclerViewWork.getParent() != null)) {
            workHeader = LayoutInflater.from(PaintBookingFeeActivity.this).inflate(//
                    R.layout.header_select_time_show, //
                    (ViewGroup) _recyclerViewWork.getParent(),//
                    false);//
        } else {
            workHeader = LayoutInflater.from(PaintBookingFeeActivity.this).inflate(R.layout.header_select_time_show, null);
        }

        //直接赋值，是不可操作的；

        //日期填充
        TextView textViewStartTimeInWorkBook = (TextView) workHeader.findViewById(R.id.textviewstarttimeinworkbookshow);

        //日期的最终格式
        String useTime = extra_paintBookingPayFee.getUseTime();

        //默认日期填充是当天的日期
        if (textViewStartTimeInWorkBook != null) {
            //该日期携带有时分秒，要人为去掉
            if (extra_paintBookingPayFee != null) {
                textViewStartTimeInWorkBook.setText(CommUtils.getTimeHasNoMMddss(useTime));
            }
        }

        return workHeader;
    }

    //添加footerView
    private View getFooterView(RecyclerView _recyclerViewWork) {

        View workFooter;
        if ((_recyclerViewWork != null) && (_recyclerViewWork.getParent() != null)) {
            workFooter = LayoutInflater.from(PaintBookingFeeActivity.this).inflate(//
                    R.layout.footer_select_time, //
                    (ViewGroup) _recyclerViewWork.getParent(),//
                    false);//
        } else {
            workFooter = LayoutInflater.from(PaintBookingFeeActivity.this).inflate(R.layout.footer_select_time, null);
        }

        //支付金额的文本
        TextView textViewMoney = (TextView) workFooter.findViewById(R.id.textviewmoney);
        //支付的列表
        RecyclerView recyclerViewInBookingPayFooter = (RecyclerView) workFooter.findViewById(R.id.recyclerViewInBookingPayFooter);

        recyclerViewInBookingPayFooter.setLayoutManager(new MyLinearLayoutManager(PaintBookingFeeActivity.this));

        //填充适配器
        if (extra_paintBookingPayFee != null) {

            BigDecimal bigDecimal = extra_paintBookingPayFee.getPrice();

            String priceString = "";

            if (bigDecimal != null) {
//                priceString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL)+ CommUtils.formatComma2BigDecimal(bigDecimal).toString()+ StringUtils.getString(R.string.unitmoney);
                priceString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(bigDecimal).toString();
            } else {
                priceString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.0).toString();
            }

            textViewMoney.setText(priceString);

            //PayFeeWayFooter payFeeWayFooter = new PayFeeWayFooter(R.layout.bookingpayfooteradapter, extra_paintBookingPayFee.getPayTypeList());
            payFeeWayFooter = new PayFeeWayFooter(R.layout.bookingpayfooteradapter, footerDataResources);

//            2023-11-04 13:50 测试代码
//            PayTypeListBean payTypeListBean = new PayTypeListBean();
//            payTypeListBean.setPayTypeName("月付-测试代码");
//            footerDataResources.add(payTypeListBean);

            recyclerViewInBookingPayFooter.setAdapter(payFeeWayFooter);
            payFeeWayFooter.notifyDataSetChanged();

            //选中支付的逻辑
            payFeeWayFooter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                    PayTypeListBean payTypeListBean = (PayTypeListBean) adapter.getItem(position);

                    if (payTypeListBean != null) {

                        int isChecked = payTypeListBean.getIsChecked();

//                        if (isChecked == 0) {
//
//                            //如果没有选中 ，那么设置选中，
//                            payTypeListBean.setIsChecked(1);
//                            payFeeWayFooter.notifyItemChanged(position);
//
//                        } else if (isChecked == 1) {
//
//                            //如果选中，那么设置未选中
//                            payTypeListBean.setIsChecked(0);
//                            payFeeWayFooter.notifyItemChanged(position);
//
//                        }

                        if (isChecked == 0) {

                            for (int index = 0; index < extra_paintBookingPayFee.getPayTypeList().size(); index++) {

                                if (index == position) {

                                    extra_paintBookingPayFee.getPayTypeList().get(index).setIsChecked(1);
//                                    payTypeListBean.setIsChecked(1);

                                } else {

                                    extra_paintBookingPayFee.getPayTypeList().get(index).setIsChecked(0);
//                                  payTypeListBean.setIsChecked(0);

                                }

                            }

                        } else if (isChecked == 1) {//如果当前状态是已经被选中的状态

                            //全部置空
                            for (int ind = 0; ind < extra_paintBookingPayFee.getPayTypeList().size(); ind++) {

                                extra_paintBookingPayFee.getPayTypeList().get(ind).setIsChecked(0);
//                                payTypeListBean.setIsChecked(0);

                            }

                        }

                        if (payFeeWayFooter != null) {
                            payFeeWayFooter.notifyDataSetChanged();
                        }

                    }

                }
            });

        }

        return workFooter;
    }

    /*
     * @Author:itchenqi175@163.com
     * @Time:2023-10-12  15:31
     * @Description:支付方式的适配器
     */
    private class PayFeeWayFooter extends BaseQuickAdapter<PayTypeListBean, BaseViewHolder> {

        public PayFeeWayFooter(int layoutResId, @Nullable List<PayTypeListBean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder baseViewHolder, PayTypeListBean payTypeListBean) {

            if (payTypeListBean != null) {

                //支付方式的图标
                //支付方式的名称
                String name = payTypeListBean.getPayTypeName();
                //支付id
                String payType = payTypeListBean.getPayType();
                int isChecked = payTypeListBean.getIsChecked();

                //支付图标
                ImageView imageViewPayIcon = (ImageView) baseViewHolder.getView(R.id.imageviewpayicon);

                //支付方式的文字信息
                TextView textViewPayName = (TextView) baseViewHolder.getView(R.id.textviewpayname);

                //选中状态
                CheckBox checkBoxInPayFee = (CheckBox) baseViewHolder.getView(R.id.checkboxinpayfee);

                //底部的一个线条
                TextView textViewAdapterBottomHelper = (TextView) baseViewHolder.getView(R.id.textViewAdapterBottomHelper);

                int indexPositon = getItemPosition(payTypeListBean);

                if (indexPositon == getData().size() - 1) {
                    textViewAdapterBottomHelper.setVisibility(View.VISIBLE);
                } else {
                    textViewAdapterBottomHelper.setVisibility(View.GONE);
                }


                //设置图标
                textViewPayName.setText(name);

                if (TextUtils.equals(payType, PayType.PAYTYPE_PAINTMONEY.getIndex())) {//喷涂币

                    //加载左侧商品图片内容
                    Glide.with(PaintBookingFeeActivity.this)//
                            .load(R.drawable.icon_mmny)//
                            .into(imageViewPayIcon);//

                    //.transition(withCrossFade())//
                    //.placeholder(R.drawable.icon_errorfang)//
                    //.error(R.drawable.icon_errorfang)
                    //.fallback(R.drawable.icon_errorfang)//

                } else if (TextUtils.equals(payType, PayType.PAYTYPE_ALIPAY.getIndex())) {//微信支付

                    //加载左侧商品图片内容
                    Glide.with(PaintBookingFeeActivity.this)//
                            .load(R.drawable.umeng_socialize_alipay)//umeng_socialize_wechat
                            .into(imageViewPayIcon);//

                    //.transition(withCrossFade())//
                    //.placeholder(R.drawable.icon_errorfang)//
                    //.error(R.drawable.icon_errorfang)
                    //.fallback(R.drawable.icon_errorfang)//

                } else if (TextUtils.equals(payType, PayType.PAYTYPE_WECHAT.getIndex())) {//支付宝支付

                    //加载左侧商品图片内容
                    Glide.with(PaintBookingFeeActivity.this)//
                            .load(R.drawable.umeng_socialize_wechat)//
                            .into(imageViewPayIcon);//

                    //.transition(withCrossFade())//
                    //.placeholder(R.drawable.icon_errorfang)
                    //.error(R.drawable.icon_errorfang)
                    //.fallback(R.drawable.icon_errorfang)

                } else if (TextUtils.equals(payType, PayType.PAYTYPE_MOUTH_PAY.getIndex())) {//喷涂币月结算

                    Glide.with(PaintBookingFeeActivity.this)
                            .load(R.drawable.icon_mmou)
                            .into(imageViewPayIcon);

                } else {

                    Glide.with(PaintBookingFeeActivity.this)
                            .load(R.drawable.icon_payoth)
                            .into(imageViewPayIcon);

                }

                //选中的变换
                if (isChecked == 1) {//表示选中
                    checkBoxInPayFee.setChecked(true);
                } else if (isChecked == 0) {
                    checkBoxInPayFee.setChecked(false);
                }
            }
        }
    }

    @Override
    protected void gainDatas() {

        //直接获取结算的接口；
        if (NetworkUtils.isConnected()) {

            getServerDatas();

        } else {
            netWorkError();
        }

    }

    private void getServerDatas() {

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETRESERVATIONFORSITEANDPAY_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getReservationForSiteAndPay_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        //addLogUpLoadInfo.setHashMapParameter(map);

        //做上传的json
        //String jsonUpLoad = JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue);
//       String jsonUpLoad = JSON.toJSONString(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getReservationForSiteAndPay(RequestBody.create(extra_paint_booking_payfee_parameter,
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(PaintBookingFeeActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<PaintBookingPayFee>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);

                        //如果有报错要特别提示

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

//                        CommUtils.checkMaterialDialog(materialDialog);
                        //进度圈圈
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);

                    }
                }).subscribe(new Consumer<PaintBookingPayFee>() {
                    @Override
                    public void accept(PaintBookingPayFee paintBookingPayFeeValue) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        if (paintBookingPayFeeValue != null) {

//                       LogUtils.json(ConstantSign.LOGCAT_NOMAL + "paintBookingPayFeeValue=", paintBookingPayFeeValue);
                            extra_paintBookingPayFee = paintBookingPayFeeValue;

                            if (mDataResources != null && !mDataResources.isEmpty()) {
                                mDataResources.clear();
                            }

                            if (mDataResources != null) {
                                mDataResources.addAll(paintBookingPayFeeValue.getSiteList());
                            }

                            //重新刷新页面
                            if (bookingOutsideAdapter != null) {
                                bookingOutsideAdapter.notifyDataSetChanged();
                            }

                            //------------------------------------------------
                            if (footerDataResources != null && !footerDataResources.isEmpty()) {
                                footerDataResources.clear();
                            }

                            if (footerDataResources != null) {
                                footerDataResources.addAll(paintBookingPayFeeValue.getPayTypeList());
                            }

                            if (payFeeWayFooter != null) {
                                payFeeWayFooter.notifyDataSetChanged();
                            }

                            //------------------------------------------------


                        }

                    }
                }, new ErrorConsumer() {
                    @Override
                    protected void error(ApiException apiException) {

                        //页面报错；
                        CommUtils.checkMaterialDialog(materialDialog);

                        if (apiException != null) {
                            ToastUtils.showShort(apiException.getDisplayMessage());
                        }

                    }
                });

    }

    @Override
    protected void methodBack() {
        methodBackFinish();
    }

    //处理微信支付的逻辑
    private void method_paymentWeChatSDK(final WechatPayBean _wechatPayBean) {

        try {

            //LogUtils.d("itchen-----微信支付内部 method_paymentWeChatSDK ");

            PayReq req = new PayReq();
            //原始代码
            req.appId = _wechatPayBean.getAppid();
            req.partnerId = _wechatPayBean.getPartnerid();//json.getString("partnerid");
            req.prepayId = _wechatPayBean.getPrepayid();//json.getString("prepayid");
            req.nonceStr = _wechatPayBean.getNoncestr();//json.getString("noncestr");
            req.timeStamp = _wechatPayBean.getTimestamp();//json.getString("timestamp");
            req.packageValue = _wechatPayBean.getPkg();//json.getString("package");
            req.sign = _wechatPayBean.getSign();//json.getString("sign");
            //req.extData = "app data"; // optional//额外携带信息暂时不处理

            // 在支付之前，如果应用没有注册到微信，应该先调用IWXMsg.registerApp将应用注册到微信
            mWinXinApi.sendReq(req);

        } catch (Exception e) {

            //微信本身的异常 仍然停留在该界面，让他勾选其他支付方式。
            if (e != null) {
                ToastUtils.showShort(R.string.wechat_error + getString(R.string.wechat_error_info) + e.getMessage());
            } else {
                ToastUtils.showShort(R.string.wechat_error);
            }

        }

    }

    /**
     * 支付宝支付业务
     * 2018年11月22日的时候发现新版的支付宝支付 需要添加权限
     */
    private void method_paymentAlipaySDK(final AlipayPayBean _alipayPayBean) {

        Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                PayTask alipay = new PayTask(PaintBookingFeeActivity.this);
                //2020-5-25 17:28:30 第二个参数 的意思是：是否展开支付宝调用时候转圈的进度长条，等待弹窗进度条
                Map<String, String> result = alipay.payV2(_alipayPayBean.getPayInfo(), true);
                Message msg = new Message();
                msg.what = SDK_PAY_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };

        Thread payThread = new Thread(payRunnable);
        payThread.start();
    }

    //支付面板的支付方式：喷涂币支付 调用接口；密码暂时不用
    private void method_paymentPanelOrWechatOrAliPay(String _payType, String _passwordStringPass) {

//                添加真实的填充数据
//                {
//                        "useTime": "2023-10-12", //预约日期
//                        "siteList": [
//                             {
//                            "spraySiteId": 4, //房间ID
//                            "siteTimeSpans": [
//                                {
//                                "siteTimeSpanId": 31 //时段ID
//                               }
//                              ] //预约时段集合
//                         }
//                   ] //房间集合
//                }

        HashMap<String, Object> map = new HashMap<>();
//      map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());
        map.put(Parameterkey.useTime, CommUtils.getTimeHasNoMMddss(extra_paintBookingPayFee.getUseTime()));//预约日期  "useTime": "2023-10-12", //预约日期
        map.put(Parameterkey.finalAmount, extra_paintBookingPayFee.getPrice());//支付的金额
        //map.put(Parameterkey.payMode, PayType.PAYTYPE_PAINTMONEY.getIndex());//支付的方式，指定是 喷涂币支付
        map.put(Parameterkey.payMode, _payType);//支付的方式，指定是 喷涂币支付
//        map.put(Parameterkey.password, _passwordStringPass);

        if (siteList_upLoad != null && !siteList_upLoad.isEmpty()) {
            siteList_upLoad.clear();
        }

        if (extra_paintBookingPayFee != null) {

            //for遍历
            if ((extra_paintBookingPayFee.getSiteList() != null) && (!extra_paintBookingPayFee.getSiteList().isEmpty())) {

                for (BookingOutsideBean itemOutSide : extra_paintBookingPayFee.getSiteList()) {

                    if (itemOutSide != null) {

                        //传递的对象外层包裹；
                        PaintBookIngSiteOutSideUpLoad paintBookIngSiteOutSideUpLoad = new PaintBookIngSiteOutSideUpLoad();
                        paintBookIngSiteOutSideUpLoad.setSpraySiteId(itemOutSide.getSpraySiteId());

                        for (BookingInsideBean itemInSide : itemOutSide.getSiteTimeSpans()) {

                            if (itemInSide != null) {

                                //创建一个 此房间的 时间段的接收器，并且给该时间段设置到外侧的房间号；
                                PaintBookIngSiteInSideUpLoad paintBookIngSiteInSideUpLoad = new PaintBookIngSiteInSideUpLoad();
                                paintBookIngSiteInSideUpLoad.setSiteTimeSpanId(itemInSide.getSiteTimeSpanId());

                                if (paintBookIngSiteOutSideUpLoad.getSiteTimeSpans() != null) {
                                    paintBookIngSiteOutSideUpLoad.getSiteTimeSpans().add(paintBookIngSiteInSideUpLoad);
                                }

//                                      LogUtils.json(ConstantSign.LOGCAT_NOMAL + "这条 预约喷涂房间段 的有效数据是--itemOutSide", itemOutSide);
                                LogUtils.json(ConstantSign.LOGCAT_NOMAL + "这条 预约时间段 的有效数据是-----itemInSide--", itemInSide);

                            }

                        }

                        //------------------------------------------------------------------------------------------

                        //这条有效数据要加到 上传对象之中;
                        if (siteList_upLoad != null) {
                            //如果有选中的再添加
                            if ((paintBookIngSiteOutSideUpLoad.getSiteTimeSpans() != null) && (!paintBookIngSiteOutSideUpLoad.getSiteTimeSpans().isEmpty())) {
                                siteList_upLoad.add(paintBookIngSiteOutSideUpLoad);
                            }
                        }

//                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "这条 预约喷涂房间段 的有效数据是--itemOutSide--所属房间号是-->" + itemOutSide.getSiteNo() + "房间号id-->" + itemOutSide.getSpraySiteId());

                    }
                }

            } else {
                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "获取的时间段 是空值");
            }
        } else {
            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "extra_paintBookingPayFee 是空值");
        }

        map.put(Parameterkey.siteList, siteList_upLoad);//房间和房间内的时间段选择器

        //--------------------------------------------------------------------------------------

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SUBMITRESERVATIONFORSITEANDPAY_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.submitReservationForSiteAndPay_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .submitReservationForSiteAndPay(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(PaintBookingFeeActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<PayParameterResult>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

//                        CommUtils.checkMaterialDialog(materialDialog);
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);

                    }
                }).subscribe(new Consumer<PayParameterResult>() {
                    @Override
                    public void accept(PayParameterResult payParameterResultValue) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        //对于这种判断哪种支付方式
                        if (TextUtils.equals(_payType, PayType.PAYTYPE_PAINTMONEY.getIndex())) {

                            //喷涂币到这里 算是支付完毕；
                            //提示，关闭该页面。
                            method_handler_success();

                        } else if (TextUtils.equals(_payType, PayType.PAYTYPE_MOUTH_PAY.getIndex())) {

                            //月结算 到这里就算结束，执行支付完毕的逻辑；
                            method_handler_success();

                        } else if (TextUtils.equals(_payType, PayType.PAYTYPE_WECHAT.getIndex())) {

                            //微信支付SDK调起

                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                                //有权限设置
                                if (!AndPermission.hasPermissions(mActivityInstance, Permission.READ_PHONE_STATE)//
                                        || !AndPermission.hasPermissions(mActivityInstance, Permission.WRITE_EXTERNAL_STORAGE)//
                                        || !AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE)) {//

                                    CommUtils.checkMaterialDialog(materialDialog);

                                    materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_PHONESTATE, new AuthorityCallbackListener() {
                                        @Override
                                        public void doSomeThing() {

                                            CommUtils.checkMaterialDialog(materialDialog);

                                            //2018年11月22日发现支付宝需要添加权限
                                            AndPermission.with(PaintBookingFeeActivity.this)
                                                    .runtime()
                                                    .permission(Permission.READ_PHONE_STATE,//
                                                            Permission.WRITE_EXTERNAL_STORAGE,//
                                                            Permission.READ_EXTERNAL_STORAGE)//
                                                    .rationale(new RuntimeRationale())
                                                    .onGranted(new Action<List<String>>() {
                                                        @Override
                                                        public void onAction(List<String> data) {

                                                            //LogUtils.d("itchen---->执行调用 method_paymentWeChatSDK---");

                                                            method_paymentWeChatSDK(payParameterResultValue.getWechatPay());

                                                        }
                                                    }).onDenied(new Action<List<String>>() {
                                                        @Override
                                                        public void onAction(List<String> permissions) {
                                                            if (AndPermission.hasAlwaysDeniedPermission(PaintBookingFeeActivity.this, permissions)) {
                                                                (new PermissionSetting(PaintBookingFeeActivity.this)).showSetting(ConstantApi.PERMISSION_NORMAL, PaintBookingFeeActivity.this, permissions);
                                                            }
                                                        }
                                                    }).start();
                                        }
                                    });

                                } else {
                                    //支付宝SDK调起
                                    method_paymentWeChatSDK(payParameterResultValue.getWechatPay());
                                }


                            } else {

                                //微信支付
                                //android大于android13
                                if (!XXPermissions.isGranted(mActivityInstance, com.hjq.permissions.Permission.READ_PHONE_STATE)) {//

                                    CommUtils.checkMaterialDialog(materialDialog);

                                    materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_PHONESTATE, new AuthorityCallbackListener() {
                                        @Override
                                        public void doSomeThing() {

                                            CommUtils.checkMaterialDialog(materialDialog);

                                            XXPermissions.with(PaintBookingFeeActivity.this)
                                                    // 适配分区存储应该这样写
                                                    //.permission(Permission.Group.STORAGE)
                                                    // 不适配分区存储应该这样写
//                                                        .permission(com.hjq.permissions.Permission.MANAGE_EXTERNAL_STORAGE)//
                                                    .permission(com.hjq.permissions.Permission.READ_PHONE_STATE)//
//                                                    .interceptor(new PermissionInterceptor())
                                                    .request(new OnPermissionCallback() {

                                                        @Override
                                                        public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                                            if (!allGranted) {
                                                                return;
                                                            }

                                                            Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                                                    PermissionNameConvert.getPermissionString(PaintBookingFeeActivity.this, permissions)));

                                                            //LogUtils.d("itchen---->执行调用 method_paymentWeChatSDK---");
                                                            method_paymentWeChatSDK(payParameterResultValue.getWechatPay());

                                                        }
                                                    });
                                        }
                                    });

                                } else {

                                    //支付宝SDK调起
                                    method_paymentWeChatSDK(payParameterResultValue.getWechatPay());

                                }

                            }

                        } else if (TextUtils.equals(_payType, PayType.PAYTYPE_ALIPAY.getIndex())) {

                            //支付宝支付逻辑。
                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                                //有权限设置
                                if (!AndPermission.hasPermissions(mActivityInstance, Permission.READ_PHONE_STATE)//
                                        || !AndPermission.hasPermissions(mActivityInstance, Permission.WRITE_EXTERNAL_STORAGE)//
                                        || !AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE)) {//

                                    CommUtils.checkMaterialDialog(materialDialog);

                                    materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_PHONESTATE, new AuthorityCallbackListener() {
                                        @Override
                                        public void doSomeThing() {

                                            CommUtils.checkMaterialDialog(materialDialog);

                                            //2018年11月22日发现支付宝需要添加权限
                                            AndPermission.with(PaintBookingFeeActivity.this)
                                                    .runtime()
                                                    .permission(Permission.READ_PHONE_STATE,//
                                                            Permission.WRITE_EXTERNAL_STORAGE,//
                                                            Permission.READ_EXTERNAL_STORAGE)//
                                                    .rationale(new RuntimeRationale())
                                                    .onGranted(new Action<List<String>>() {
                                                        @Override
                                                        public void onAction(List<String> data) {

                                                            //LogUtils.d("itchen---->执行调用 method_paymentAlipaySDK---");
                                                            //支付宝SDK调起
                                                            method_paymentAlipaySDK(payParameterResultValue.getAlipayPay());

                                                        }
                                                    }).onDenied(new Action<List<String>>() {
                                                        @Override
                                                        public void onAction(List<String> permissions) {
                                                            if (AndPermission.hasAlwaysDeniedPermission(PaintBookingFeeActivity.this, permissions)) {
                                                                (new PermissionSetting(PaintBookingFeeActivity.this)).showSetting(ConstantApi.PERMISSION_NORMAL, PaintBookingFeeActivity.this, permissions);
                                                            }
                                                        }
                                                    }).start();
                                        }
                                    });

                                } else {
                                    //支付宝SDK调起
                                    method_paymentAlipaySDK(payParameterResultValue.getAlipayPay());
                                }

                            } else {

                                //大于android13
                                //有权限设置
                                if (!XXPermissions.isGranted(mActivityInstance, com.hjq.permissions.Permission.READ_PHONE_STATE)) {//

                                    CommUtils.checkMaterialDialog(materialDialog);

                                    materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_PHONESTATE, new AuthorityCallbackListener() {
                                        @Override
                                        public void doSomeThing() {
                                            //2018年11月22日发现支付宝需要添加权限
                                            CommUtils.checkMaterialDialog(materialDialog);
//

                                            XXPermissions.with(PaintBookingFeeActivity.this)
                                                    // 适配分区存储应该这样写
                                                    //.permission(Permission.Group.STORAGE)
                                                    // 不适配分区存储应该这样写
//                                                        .permission(com.hjq.permissions.Permission.)//
                                                    .permission(com.hjq.permissions.Permission.READ_PHONE_STATE)//
                                                    .interceptor(new PermissionInterceptor())
                                                    .request(new OnPermissionCallback() {

                                                        @Override
                                                        public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                                            if (!allGranted) {
                                                                return;
                                                            }

                                                            Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                                                    PermissionNameConvert.getPermissionString(PaintBookingFeeActivity.this, permissions)));

                                                            //支付宝SDK调起
                                                            method_paymentAlipaySDK(payParameterResultValue.getAlipayPay());

                                                        }
                                                    });
                                        }
                                    });

                                } else {
                                    //支付宝SDK调起
                                    method_paymentAlipaySDK(payParameterResultValue.getAlipayPay());
                                }

                            }

                        } else {
                            //CommUtils.displayToastShort(AccountPayActivity.this, "支付错误");
                            ToastUtils.showShort(StringUtils.getString(R.string.alipay_pay_error));
                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        //页面报错；
                        CommUtils.checkMaterialDialog(materialDialog);

                        //如果非20000的有必要提示就可以在这里用户自己提示给用户
                        if (apiException != null) {
                            ToastUtils.showLong(apiException.getDisplayMessage());
                        }

                    }
                });


    }

    //支付成功的处理页面
    private void method_handler_success() {

        methodSingleSubmitSuccessCustomTitle(PaintBookingFeeActivity.this, getString(R.string.alipay_pay_success), new DoSomeThingListener() {
            @Override
            public void doSomeThing() {

                //通知上一个页面刷新
                EventPaintBookingMain eventPaintBookingMain = new EventPaintBookingMain();
                eventPaintBookingMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_PAINTBOOKING_MAIN_PAGE);
                EventBus.getDefault().post(eventPaintBookingMain);

                //关闭该页面
                methodBackFinish();

            }
        });

    }

    //喷涂币支付
    private void popKeyboard() {

        //弹窗的预备工作
        closePayDialog(payDialogPanel);

        payDialogPanel = BottomDialog.create(getSupportFragmentManager())//

                .setViewListener(new BottomDialog.ViewListener() {//
                    @Override
                    public void bindView(View view) {//

                        //携带三个参数去创建支付面板。
                        initPayView(view);

                    }
                }).setLayoutRes(R.layout.paydialog_daguanjia)//
                .setDimAmount(0.5f)//
                .setCancelOutside(false)//支付宝的弹窗之外不可再次点击消失
                .setTag("paymentPaintBooking")//
                .show();//

    }

    /**
     * 弹出密码软键盘
     */
    private void initPayView(View _view) {

        final PasswordView passwordView = (PasswordView) _view.findViewById(R.id.pwd_view);

        //每次弹出前都清空一遍密码
        deletePassword(passwordView);

        // 添加密码输入完成的响应
        passwordView.setOnFinishInput(new OnPasswordInputFinish() {
            @Override
            public void inputFinish() {

                // 输入完成后我们简单显示一下输入的密码
                // 也就是说——>实现你的交易逻辑什么的在这里写
                //CommUtils.displayToastShort(AccountPayActivity.this, passwordView.getStrPassword());

                String password = passwordView.getStrPassword();
                //passwordStringPass = Base64.getEncoder().encodeToString(password.getBytes("utf-8"));
//                passwordStringPass = EncodeUtils.base64Encode2String(password.getBytes(Charset.defaultCharset()));
                //String encodeFirst = EncryptUtils.encryptMD5ToString();
                String passwordStringPass = StringCodeUtils.doubleMD5(password);
                LogUtils.d("itchen--double加密之后-" + passwordStringPass);
                //规则：两次MD5加密
                //String passwordStringPass = EncryptUtils.encryptMD5ToString(EncryptUtils.encryptMD5ToString(password));
//                String passwordStringPass = EncryptUtils.encryptMD5ToString(encodeFirst);
//                LogUtils.d("itchen--第二次加密之后-" + passwordStringPass);
                //LogUtils.d("itchen--解密之后-----"+new String(EncodeUtils.base64Decode(passwordStringPass)));

                //首先是关闭面板，不关闭可能密码支付错误了，重试功能
                closePayDialog(payDialogPanel);

                //立即删除掉密码内容
                //deletePassword(passwordView);

                //输入完毕,调用接口验证密码正确性,调用大管家支付接口
//                getPayToken(beforeOrderNoPass);

                //输入完毕支付密码，支付圈圈，接口调用
                //method_paymentPanel(passwordStringPass);


            }
        });

        /**
         * 可以用自定义控件中暴露出来的cancelImageView方法，重新提供相应 如果写了，会覆盖我们在自定义控件中提供的响应
         * 可以看到这里toast显示 "Biu Biu Biu"而不是"Cancel"
         */
        passwordView.getLayoutCloseCancel().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ToastUtils.showShort(R.string.pop_pay_cancel);

                //先让面板内的密码数字重置空
                deletePassword(passwordView);

                //2018年04月16日添加关闭当前面板的逻辑
                closePayDialog(payDialogPanel);

            }
        });

        //2017年2月09日.忘记密码按钮,此处暂时保留,效果图没有,但是以后有
//        passwordView.getForgetTextView().setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //加载方式的携带->1：社区公告 2：帮助中心 3：个人中心我的钱包 4:我的钱包充值界面 5我的钱包忘记密码界面
//                method_toWallet(ConstantApi.WEBVIEWFLAG_WALLET_PASSWORD, ConstantApi.ISJUMPFROMWALLET_PASSWORD);//加载忘记密码链接.
//
//            }
//        });

    }

    /**
     * 删除支付面板密码内容
     */
    private void deletePassword(PasswordView _passwordView) {

        for (int index = 0; index < 6; index++) {//密码删除

            if (_passwordView != null) {

                _passwordView.method_delete(11);
                //LogUtils.d("itchen-->textIndex=="+index);//确实是执行6次.
            } else {
                //应该是让面板重新隐藏再显示出来
                //2017年02月16日,有时间了重新加上.
            }

        }

    }

    /**
     * 关闭弹窗内容
     */
    private void closePayDialog(BaseBottomDialog _payDialogPanel) {

        if (_payDialogPanel != null) {
            if (_payDialogPanel.getDialog() != null && _payDialogPanel.getDialog().isShowing()) {
                _payDialogPanel.dismiss();
                _payDialogPanel = null;
                //payDialogPanel.dismissAllowingStateLoss();
            }
        }

    }

    @Override
    public void processExtraData() {

        //携带过来的数据，如果携带的数据是空，那么就直接获取接口
        //use the data received here
        Bundle bundle = this.getIntent().getExtras();

        if (bundle != null) {
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + extra_jumpfrom_where);

            //携带档案的id.是大范畴的
            extra_paintBookingPayFee = bundle.getParcelable(ExtraKey.EXTRA_PAINTBOOKINGPAYFEE);

            //重新调用卡的参数
            extra_paint_booking_payfee_parameter = bundle.getString(ExtraKey.EXTRA_PAINT_BOOKING_PAYFEE_PARAMETER);

            if (extra_paintBookingPayFee != null) {

                if (mDataResources != null && !mDataResources.isEmpty()) {
                    mDataResources.clear();
                }

                if (mDataResources != null) {
                    mDataResources.addAll(extra_paintBookingPayFee.getSiteList());
                }

                //底部的适配器的列表数据内容，拆开写是为了刷新
                if (footerDataResources != null && !footerDataResources.isEmpty()) {
                    footerDataResources.clear();
                }

                //填充支付方式列表
                if (footerDataResources != null) {
                    footerDataResources.addAll(extra_paintBookingPayFee.getPayTypeList());
                }

                LogUtils.json(ConstantSign.LOGCAT_NOMAL + "支付数据携带---extra_paintBookingPayFee--->" + extra_paintBookingPayFee);
            }

        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThreadEventPay(EventPay eventPay) {

        if (eventPay != null) {

            int errorCode = eventPay.getMessage();
            //isOpenWechart = false;//itchen retain先这样，等调试接口再处理

            if (errorCode == BaseResp.ErrCode.ERR_OK) {

                //获取服务器端告知支付成功的接口,然后跳转到结算结果页。
//                gainOrderState(payTokenForPay, 1);

                method_handler_success();

            } else if (errorCode == BaseResp.ErrCode.ERR_USER_CANCEL) {

//                CommUtils.displayToastShort(PaintBookingFeeActivity.this, "支付取消");
//                ToastUtils.showShort("支付取消");
                //2018年03月20日逻辑，微信支付失败仍然停留在此界面。
                //gainOrderStateFail(payTokenForPay,0);

                ToastUtils.showShort(getResources().getString(R.string.pop_pay_cancel));

            } else if (errorCode == BaseResp.ErrCode.ERR_AUTH_DENIED) {

//                CommUtils.displayToastShort(PaintBookingFeeActivity.this, "支付失败");
//                ToastUtils.showShort("支付失败");
                //gainOrderStateFail(payTokenForPay,0);

                ToastUtils.showShort(getResources().getString(R.string.wechat_pay_failed));

            } else if (errorCode == BaseResp.ErrCode.ERR_COMM) {

                //LogUtils.d("itchen-----执行微信支付错误逻辑");

//                CommUtils.displayToastShort(PaintBookingFeeActivity.this, "支付错误");
//                ToastUtils.showShort("支付错误");

                ToastUtils.showShort(getResources().getString(R.string.wechat_pay_wrong));

                //gainOrderStateFail(payTokenForPay,0);
            } else if (errorCode == BaseResp.ErrCode.ERR_SENT_FAILED) {

//                CommUtils.displayToastShort(PaintBookingFeeActivity.this, "支付发送失败");

//                ToastUtils.showShort("支付发送失败");
                ToastUtils.showShort(getResources().getString(R.string.wechat_pay_send_message_fail));

                //gainOrderStateFail(payTokenForPay,0);
            } else if (errorCode == BaseResp.ErrCode.ERR_UNSUPPORT) {

//                CommUtils.displayToastShort(PaintBookingFeeActivity.this, "不支持错误");

//                ToastUtils.showShort("不支持错误");
                ToastUtils.showShort(getResources().getString(R.string.wechat_pay_not_supported_wrong));

                //gainOrderStateFail(payTokenForPay,0);
            } else {
                //retain
//                ToastUtils.showShort("未知错误");
                ToastUtils.showShort(getResources().getString(R.string.wechat_pay_unkown_wrong));
            }


        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        closePayDialog(payDialogPanel);

        if (extra_paintBookingPayFee != null) {

            if (extra_paintBookingPayFee.getSiteList() != null) {
                extra_paintBookingPayFee.getSiteList().clear();
                if (bookingOutsideAdapter != null) {
                    bookingOutsideAdapter.notifyDataSetChanged();
                    bookingOutsideAdapter = null;
                }
            }

            extra_paintBookingPayFee = null;
        }

        EventBus.getDefault().unregister(this);

    }
}